package com.sun.showcase.controller.app;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sun.showcase.biz.exception.BusinessException;
import com.sun.showcase.biz.sms.SmsComponent;
import com.sun.showcase.client.vo.SmsPojo;
import com.sun.showcase.pojo.Result;

@RestController
@RequestMapping(value="/app/sms") 
public class SmsApp {

	
	@Autowired
	private SmsComponent smsComponent;
	
	
	/**
	 * 获取短信
	 * 说明参数type：1、登陆;2、修改信息;
	 */
	@RequestMapping(value="send")
	public Result send(@Valid SmsPojo pojo,BindingResult bindingResult) {
		
		if(bindingResult.hasErrors()) 
			throw new BusinessException(bindingResult.getFieldError().getDefaultMessage());
		
		Result result = new Result();
		
		smsComponent.send(pojo.getPhone(), pojo.getType());
		
		result.setSuccess(true);
		result.setMsg("发送成功！");
		
		
		return result;
	}
}
